package cn.fxl.basic.controller;

import cn.fxl.order.domain.OrderPetAcquisition;
import cn.fxl.order.service.IOrderPetAcquisitionService;
import cn.fxl.pet.domain.Pet;
import cn.fxl.pet.service.IPetService;
import io.netty.util.CharsetUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.index.PathBasedRedisIndexDefinition;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RocketMQMessageListener(topic = "queue_test_topic",selectorExpression="*",consumerGroup = "queue_group_test")
public class RocketMQMsgListener implements RocketMQListener<MessageExt> {
    @Autowired
    private IOrderPetAcquisitionService iOrderPetAcquisitionService;
    @Override
    public void onMessage(MessageExt messageExt) {
        byte[] body = messageExt.getBody();
        String msg = new String(body, CharsetUtil.UTF_8);
        System.out.println("收到的消息"+msg+"----------------------");
        long l = Long.parseLong(msg);
        OrderPetAcquisition order = iOrderPetAcquisitionService.getOne(l);
        if(order.getState()!=1){
            iOrderPetAcquisitionService.remove(l);
        }
    }
}
